import axios from 'axios';
import 'nprogress/nprogress.css';
import NProgress from 'nprogress';

const mockAjax = axios.create({
    baseURL: '/mock',
    timeout: 1000,
});

mockAjax.interceptors.request.use(config => {
    NProgress.start();
    return config;
});

mockAjax.interceptors.response.use(
    response => {
        NProgress.done();
        return response.data;
    },
    error => {
        NProgress.done();
        return Promise.reject(new Error(error.message));
    }
);

export default mockAjax;
